package com;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;

/**
 * @author Sandsboy
 * @description:广州皓醒科技有限公司
 * @date :2019/11/8 15:25
 */
public class CustomBesselLine extends View {
    public CustomBesselLine(Context context) {
        this(context, null);
    }

    public CustomBesselLine(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);

        //新增test451
        //主分支master451


    }

    public CustomBesselLine(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    Paint mPaint;
    Path mPath;

    private void init() {

        mPaint = new Paint();
        mPath = new Path();
        mPaint.setStyle(Paint.Style.FILL);
        mPaint.setColor(Color.RED);
        mPaint.setStrokeWidth(10);
    }


    int DefaultHeight = 400;
    int DefaultWidth = 400;

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        int modewidth = MeasureSpec.getMode(widthMeasureSpec);
        int modeheight = MeasureSpec.getMode(heightMeasureSpec);
        int sizewidth = MeasureSpec.getSize(widthMeasureSpec);
        int sizeheight = MeasureSpec.getSize(heightMeasureSpec);


        switch (modewidth) {

            case MeasureSpec.AT_MOST://warp
                break;
            case MeasureSpec.EXACTLY://精确
                DefaultWidth = sizewidth;
                break;
        }
        switch (modeheight) {

            case MeasureSpec.AT_MOST://warp
                break;
            case MeasureSpec.EXACTLY://精确
                DefaultHeight = sizeheight;
                break;
        }

        setMeasuredDimension(sizewidth, sizeheight);

    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        drawPath(canvas);
    }


    private void drawPath(Canvas canvas) {

        mPath.moveTo(getWidth() / 2, getHeight());


        mPath.cubicTo(getWidth()/2*0.3f,getHeight()/2*0.6f,getWidth()/2*0.9f, getHeight() /2*0.4f, getWidth() / 2, getHeight() / 2);
//        mPath.quadTo(getWidth() / 4, getHeight() / 4, getWidth() / 2, getHeight() / 2);
        mPath.cubicTo(getWidth() / 2*1.1f, getHeight() / 2*0.4f,getWidth()/2*1.7f,getHeight()/2*0.6f,getWidth()/2, getHeight());



        canvas.drawPath(mPath, mPaint);

    }
}
